<?php

//UMA new
namespace App\Services;

use GuzzleHttp\Client;
use App\Traits\TestLog;

class KintoneService
{
    use TestLog;
    private $client;

    public function __construct()
    {
        $this->client = new Client();
        //$this->client->setDefaultOption('verify', base_path().'/cacert.pem');
    }
        
    /**
     * saveInfo
     *
     * @param  mixed $data
     * @return void
     */
    public function saveInfo($data)
    {
        $this->loginfo($data, "kintone datas:");
        $config = config('services.kintone');
        extract($config);
        $authorization = base64_encode($username.':'.$password);
        $response = $this->client->post($url, [
            'headers' => [
                "X-Cybozu-API-Token" => $token,
                "Authorization" => "Basic ".$authorization,
            ],
            'json' => [
                'app' => $app,
                'record' => $data,
            ]
        ]);
        $this->loginfo(json_decode($response->getBody(), true), 'kintone response:');
        return true;
    }
}
